package com.zhuoli.service.springboot.redis.repository.controller;

import com.zhuoli.service.springboot.redis.repository.core.RedisControllerService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zhuoli
 * @Date: 2018/8/27 10:25
 * @Description:
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "/redis")
@Slf4j
public class RedisController {

    private RedisControllerService redisControllerService;

    @RequestMapping(value = "/set_kv", method = RequestMethod.POST)
    public ResponseEntity setKV(@RequestParam(value = "key") String key,
                                @RequestParam(value = "value") String value) {
        return ResponseEntity.status(HttpStatus.OK).body(redisControllerService.insertKV(key, value));
    }

    @RequestMapping(value = "/get_value", method = RequestMethod.POST)
    public ResponseEntity getValue(@RequestParam(value = "key") String key) {
        return ResponseEntity.status(HttpStatus.OK).body(redisControllerService.getValue(key));
    }
}
